const { findLog, findAllLog } = require("../model/logs")

const getLoginLog = async (req, res) => {
    let page = req.query['page'] || 1;
    let count = req.query['count'] || 10;
    let counts = {
        skip: (page - 1) * count,
        limit: count - 0
    }
    let username = {
        username: req.query.name
    }
    let result = await findLog(username, counts)
    console.log(result);

    if (result) {
        res.send({ status: 200, state: true, msg: "success", data: result })
    } else {
        res.send({ status: 501, state: false, msg: "failed" })
    }
}

//查看所有日志
const getAllLoginLog = async (req, res) => {
    let query = {}
    if (req.query.name) { query.username = req.query.name }
    let result = await findAllLog(query)
    if (result) {
        res.send({ status: 1, state: true, msg: "数据获取成功", data: result })
    } else {
        res.send({ status: 0, state: false, msg: "数据获取失败" })
    }
}

module.exports = {
    getLoginLog, getAllLoginLog
}